/**
 * Copyright (c) 2003-2017 Ben Lau
 * All rights reserved.
 */
package concurrency;

import java.util.HashMap;
import java.util.UUID;

/**
 * hashMap在多线程环境下使用put操会引起列循环，原因是HashMap在并发执行put操作时会引起列循环，
 * 是因为多线程会导致HashMap的Entry链表形成环形数据结构。
 * 
 * @author liubin
 *
 */
public class HashMapDeadLoop {

	public static void main(String[] args) throws InterruptedException {
		final HashMap<String, String> map = new HashMap<>(2);
		Thread thread =  new Thread(new Runnable() {
			
			@Override
			public void run() {
				for (int i = 0; i < 10000; i++) {
					new Thread(new Runnable() {
						
						@Override
						public void run() {
							map.put(UUID.randomUUID().toString(),"");
						}
					},"ftf"+i).start();;
				}
			}
		},"ftf");
		thread.start();
		thread.join();
	}

}
